package main;

import java.io.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;

public class FileHandler {
//=========================================================================== XML HANDLING

	/**
	* loads an xmlDom from the specified file
	*
	* @param fileName The file to load
	* @return Document xmlDom loaded from the file
	* @throws Exception
	*/
	public static Document readXML(String fileName)throws Exception	{
		try {
			DocumentBuilderFactory factory  = DocumentBuilderFactory.newInstance();
			DocumentBuilder        builder  = factory.newDocumentBuilder();
			
			Document document = builder.parse(new File(fileName));
	                   return document;
	               }
	           catch(Exception e){
	                   throw new Exception("File not loaded",e);
	           }
	               
	       }
	 

//=========================================================================== TXT HANDLING
	public void writeTXT(int WriteThis,char suffix)throws Exception{
		FileOutputStream out;
		PrintStream p;
		
		try
        {
                //Neuen OutputStream mit Dateiname + symbol
                out = new FileOutputStream("spieler"+suffix+"2server.txt");

                p = new PrintStream( out );

                p.println (WriteThis);

                p.close();
        }
        catch (Exception e)
        {
        	throw new Exception("TextDatei nicht gespeichert",e);
        }
	}
	
	
	
}
